﻿<script language="jscript" runat="server">
    function LoadTextFile() {
        var fPath = String(arguments[0]), sContent = "";
        if (fPath.indexOf(":") == -1) { fPath = Server.MapPath(fPath); }
        var s = Server.CreateObject("adodb.stream");
        with (s) {
            Type = 2;
            Mode = 3;
            CharSet = "iso-8859-15";
            Open();
            LoadFromFile(fPath);
            str = ReadText(4);
            if (str.substr(0, 3) = "\xEF\xBB\xBF") { CharSet = "utf-8"; }
            else if (str.substr(0, 2) = "\xFF\xFE") { CharSet = "utf-16le"; }
            else if (str.substr(0, 2) = "\xFE\xFF") { CharSet = "utf-16be"; }
            else if (str.substr(0, 2) = "\x84\x31\x95\x33") { CharSet = "gb18030"; }
            else { CharSet = "gbk"; }
            sContent = ReadText();
            Close();
        }
        return sContent;
    }
    function Execute(fPath) {
        var sContent = LoadTextFile(fPath);
        with (this) { eval(sContent); }
    }
    function Include(fPath) {
        var sContent = LoadTextFile(fPath);
        sContent = sContent.replace(/(\x3C%\s*@)([\s\S]*?)(%\x3E)/gm, "");
        sContent = sContent.replace(/(<\!--\s*#include\s*file\s*=\s*)([\s\S]*?)(\s*-->)/gi, "");
        sContent = sContent.replace(/(<\!script\s*[\s\S]*?\s*runat\s*=\s*"server"\s*>)([\s\S]*?)(<\/script>)/gi, "<\%" + sContent + "%\>");
        sContent = sContent.replace(/(\x3C%\s*=)([\s\S]*?)(%\x3E)/gm, "<\%Response.Write($2);%\>");
        sContent = "%\>" + sContent + "<\%";
        sContent = sContent.replace(/(%\x3E)([\s\S]*?)(\x3C%)/gm, __encode);
        with (this) { eval(sContent); }
        function __encode() {
            var s = arguments[2];
            if (!s) { return ""; }
            s = s.replace(/\\/g, "\\\\");
            s = s.replace(/[\x27\x22]/gm, "\\$&");
            s = s.replace(/\n/mg, "\\n");
            s = s.replace(/\r/mg, "\\r");
            s = s.replace(/\t/mg, "\\t");
            return "\nResponse.Write(\"" + s + "\");\n";
        }
    }
    /*-----------------------------------------------------------------------------------------------------------------------------*/
    function Folders(path) {
        path = String(path || ".");
        var f = folder(path);
        var fs = [path];
        for (var i = 0; i < f.length; i++) {
            fs = fs.concat(arguments.callee(f[i]));
        }
        return fs;
        function folder(path) {
            path = String(path) || ".";
            var fc, fPath, fn = [];
            fso = fso || Server.CreateObject("Scripting.FileSystemObject");
            fPath = path.indexOf(":") == -1 ? Server.MapPath(path) : path;
            if (fso.FolderExists(fPath)) {
                fc = fso.GetFolder(fPath);
                var ef = new Enumerator(fc.SubFolders);
                for (; !ef.atEnd(); ef.moveNext()) {
                    fn.push(path + "/" + ef.item().Name);
                }
            }
            return fn;
        }
    }
    function Stream(t, m) {
        t = Number(t) || 1; m = Number(m) || 3;
        var sObj = Server.CreateObject("adodb.stream");
        with (sObj) {
            Type = t;
            Mode = m;
            Open();
            Position = 0;
        }
        return sObj;
    }
    /*-----------------------------------------------------------------------------------------------------------------------------*/
    function Header() {
        var cs = arguments[0] || "utf-8", ct = arguments[1] || "text/html", nc = arguments[2] || false;
        with (Response) {
            Clear();
            if (nc) {
                Expires = -1;
                ExpiresAbsolute = "1980-1-1 0:0:0";
                AddHeader("pragma", "no-cache")
                AddHeader("cache-control", "private")
                CacheControl = "no-cache"
            }
            Buffer = true;
            ContentType = String(ct);
            CharSet = String(cs);
        }
    }
    function Push(s) {
        Response.Flush();
    }
    function Flush() {
        Response.Flush();
    }
    function Echo(s) {
        s = String(s)
        for (var i = 1; i < arguments.length; i++) {
            s += String(arguments[i]);
        }
        Response.Write(s);
    }
    function Write(s) {
        s = String(s)
        for (var i = 1; i < arguments.length; i++) {
            s += String(arguments[i]);
        }
        Response.Write(s);
    }
    function Exit() {
        Response.End();
    }
    function Complate() {
        Response.Flush();
        Response.End()
    }
    function Goto(url) {
        url = String(url);
        Response.Write("<\script type=\"text/javascript\"> window.location.href = \"" + $encode(url) + "\";<\/script>");
        Response.Flush();
    }
    function JsFile(url) {
        url = String(url);
        Response.Write("<\script type=\"text/javascript\" src=\"" + url + "\"><\/script>");
    }
    function CssFile(url) {
        url = String(url);
        Response.Write("<link rel=\"Stylesheet\" type=\"text/css\" href=\"" + url + "\" />");
    }

    function Get(k) {
        var v = []; k = String(k);
        for (var i = 1; i <= Request.QueryString(k).Count; i++) {
            v.push(Request.QueryString(k)(i));
        }
        return v;
    }
    function Post(k) {
        var v = []; k = String(k);
        for (var i = 1; i <= Request.Form(k).Count; i++) {
            v.push(Request.Form(k)(i));
        }
        return v;
    }
    function Variables(k) {
        var v = []; k = String(k);
        for (var i = 1; i <= Request.ServerVariables(k).Count; i++) {
            v.push(Request.ServerVariables(k)(i));
        }
        return v;
    }
    function sRead(s, n) {
        with (s) {
            if (Type != 2) { Position = 0; Type = 2; }
            if (CharSet != "iso-8859-15") { Position = 0; CharSet = "iso-8859-15"; }
        }
        if (n) { var str = s.ReadText(n); } else { var str = s.ReadText(); }
        str = str.replace(/[^\u0000-\u00FF]/g, function(c) {
            switch (c) {
                case "\u20AC": return "\xA4"; case "\u0160": return "\xA6"; case "\u0161": return "\xA8";
                case "\u017D": return "\xB4"; case "\u017E": return "\xB8"; case "\u0152": return "\xBC";
                case "\u0153": return "\xBD"; case "\u0178": return "\xBE";
            }
        });
        return str;
    }
    function sWrite(s, str) {
        with (s) {
            if (Type != 2) { Position = 0; Type = 2; }
            if (CharSet != "iso-8859-15") { Position = 0; CharSet = "iso-8859-15"; }
        }
        str = String(str).replace(/[\xA4\xA6\xA8\xB4\xB8\xBC\xBD\xBE]/g, function(c) {
            switch (c) {
                case "\xA4": return "\u20AC"; case "\xA6": return "\u0160"; case "\xA8": return "\u0161";
                case "\xB4": return "\u017D"; case "\xB8": return "\u017E"; case "\xBC": return "\u0152";
                case "\xBD": return "\u0153"; case "\xBE": return "\u0178";
            }
        });
        return s.WriteText(str);
    }
    function alert() {
        s = "<\script type=\"text\/javascript\">";
        for (var i = 0; i < arguments.length; i++) {
            s += "\n alert(" + $encode(arguments[i]) + ");";
        }
        Response.Write(s + "<\/script>");
        Response.Flush();
    }
</script>

